<?php


namespace app\system\controller\vod;

use app\common\model\vod\CateModel;
use app\system\controller\BaseController;

class UploadController extends BaseController
{
  /**
   * 无需登录方法
   * @var array
   */
  protected $noLogin = ['create', 'refresh'];

  /**
   * 不检测权限方法
   * @var array
   */
  protected $noCheck = [];

  protected $mapCheck = [
      '*'=>'vod.index/index'
  ];

  /**
   * 视频模型
   * @var null
   */
  private $vodModel = null;

  /**
   * 初始化
   */
  public function __construct()
  {
    parent::__construct();
    $this->vodModel = null;
  }

  /**
   * 视频列表
   * @return string
   * @throws \Exception
   */
  public function index()
  {
    $cateModel = new CateModel();
    $cate = $cateModel->getList();
    $this->assign('cate',$cate);
    return $this->fetch();
  }

  /**
   * 获取上传签名
   * @return string
   */
  public function sign(){
    $classId = $this->request->param('class_id');
    $sourceContext = $this->request->param('source_context','');
    $config = config('cloud.tencent');
    $secretId = $config['secretId'];
    $secretKey = $config['secretKey'];
    $current = time();
    $expired = $current + 86400;  // 签名有效期：1天
    //参数列表
    $argList = [
        "secretId" => $secretId,
        "currentTimeStamp" => $current,
        "expireTime" => $expired,
        "random" => rand(),
        "sourceContext" => $sourceContext //来源上下文
    ];
    if($classId>0) $argList['classId'] = (int)$classId;
    $original = http_build_query($argList);
    return base64_encode(hash_hmac('SHA1', $original, $secretKey, true).$original);
  }

}